import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

import 'meta_human_edit_view.dart';

class MetaHumanContentView extends StatefulWidget {
  final double contentHeight;
  final bool isVertical;
  const MetaHumanContentView({super.key, this.contentHeight = 500, this.isVertical = true});

  @override
  State<MetaHumanContentView> createState() => _MetaHumanContentViewState();
}

class _MetaHumanContentViewState extends State<MetaHumanContentView> {
  @override
  Widget build(BuildContext context) {
    const double ratio = 9.0 / 16.0;
    final double bgHeight;
    final double bgWidth;
    if (widget.isVertical) {
      bgHeight = widget.contentHeight - 40;
      bgWidth = bgHeight * ratio;
    } else {
      final view = View.of(context);
      bgWidth = view.physicalSize.width / view.devicePixelRatio;
      bgHeight = bgWidth * ratio;
      debugPrint('------$bgWidth---------$bgHeight--------');
    }
    return Container(
      color: Colors.blue,
      width: double.infinity,
      height: widget.contentHeight - 40,
      child: Stack(
        alignment: Alignment.center,
        children: [
          Positioned(
              height: bgHeight,
              width: bgWidth,
              child: CachedNetworkImage(
                imageUrl:
                    'https://metastudio-sh1.obs.cn-east-3.myhuaweicloud.com:443/SYSTEM/d91ed71c7f16f66c8f47e2466c675058/5478929acaa06ea1f418835b2ea07cd7.png?AccessKeyId=WTEZCVDFUF3XHXCTPIJ8&Expires=1703894447&response-content-disposition=attachment%3B+filename*%3Dutf-8%27%27%25E5%258A%259E%25E5%2585%25AC%25E5%25AE%25A4%25E8%2583%258C%25E6%2599%25AF.png&Signature=vh6DQ9BCGzOkD%2FfBYiYTmIn2ygA%3D',
                fit: BoxFit.cover,
                useOldImageOnUrlChange: true,
              )),
          Positioned.fill(
              child: ClipRect(
            child: MetaHumanEditView(
              contentWidget: CachedNetworkImage(
                imageUrl:
                    'https://metastudio-sh1.obs.cn-east-3.myhuaweicloud.com:443/SYSTEM/95b7685ce9da27b8c50d617a5b9c0764/d6e17c256a779a0f60326be73640b777.png?AccessKeyId=WTEZCVDFUF3XHXCTPIJ8&Expires=1703743187&response-content-disposition=attachment%3B+filename*%3Dutf-8%27%2700001.png&Signature=ao3OlgbIJkP8S12AizBMhn2t0HU%3D',
              ),
              size: const Size(90, 160),
              containerWidth: bgWidth,
              containerHeight: bgHeight,
              endEditCallBack: (x, y, w, h) {
                debugPrint("x:$x,y:$y,w:$w,h:$h");
              },
            ),
          )),
        ],
      ),
    );
  }
}
